/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package gamedsl2.impl;

import gamedsl2.AbstractEntity;
import gamedsl2.AbstractEnvironment;
import gamedsl2.Event;
import gamedsl2.Gamedsl2Package;

import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.impl.EObjectImpl;

import org.eclipse.emf.ecore.util.EObjectWithInverseResolvingEList;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.ecore.util.InternalEList;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Abstract Entity</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link gamedsl2.impl.AbstractEntityImpl#getEntityTriggers <em>Entity Triggers</em>}</li>
 *   <li>{@link gamedsl2.impl.AbstractEntityImpl#getEntitySubscribers <em>Entity Subscribers</em>}</li>
 *   <li>{@link gamedsl2.impl.AbstractEntityImpl#getEnvironment <em>Environment</em>}</li>
 *   <li>{@link gamedsl2.impl.AbstractEntityImpl#getName <em>Name</em>}</li>
 *   <li>{@link gamedsl2.impl.AbstractEntityImpl#getType <em>Type</em>}</li>
 *   <li>{@link gamedsl2.impl.AbstractEntityImpl#getXPos <em>XPos</em>}</li>
 *   <li>{@link gamedsl2.impl.AbstractEntityImpl#getYPos <em>YPos</em>}</li>
 *   <li>{@link gamedsl2.impl.AbstractEntityImpl#getMass <em>Mass</em>}</li>
 *   <li>{@link gamedsl2.impl.AbstractEntityImpl#getFriction <em>Friction</em>}</li>
 *   <li>{@link gamedsl2.impl.AbstractEntityImpl#getValue <em>Value</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public abstract class AbstractEntityImpl extends EObjectImpl implements AbstractEntity {
	/**
	 * The cached value of the '{@link #getEntityTriggers() <em>Entity Triggers</em>}' reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getEntityTriggers()
	 * @generated
	 * @ordered
	 */
	protected EList<Event> entityTriggers;

	/**
	 * The cached value of the '{@link #getEntitySubscribers() <em>Entity Subscribers</em>}' reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getEntitySubscribers()
	 * @generated
	 * @ordered
	 */
	protected EList<Event> entitySubscribers;

	/**
	 * The default value of the '{@link #getName() <em>Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getName()
	 * @generated
	 * @ordered
	 */
	protected static final String NAME_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getName() <em>Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getName()
	 * @generated
	 * @ordered
	 */
	protected String name = NAME_EDEFAULT;

	/**
	 * The default value of the '{@link #getType() <em>Type</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getType()
	 * @generated
	 * @ordered
	 */
	protected static final String TYPE_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getType() <em>Type</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getType()
	 * @generated
	 * @ordered
	 */
	protected String type = TYPE_EDEFAULT;

	/**
	 * The default value of the '{@link #getXPos() <em>XPos</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getXPos()
	 * @generated
	 * @ordered
	 */
	protected static final float XPOS_EDEFAULT = 0.0F;

	/**
	 * The cached value of the '{@link #getXPos() <em>XPos</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getXPos()
	 * @generated
	 * @ordered
	 */
	protected float xPos = XPOS_EDEFAULT;

	/**
	 * The default value of the '{@link #getYPos() <em>YPos</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getYPos()
	 * @generated
	 * @ordered
	 */
	protected static final float YPOS_EDEFAULT = 0.0F;

	/**
	 * The cached value of the '{@link #getYPos() <em>YPos</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getYPos()
	 * @generated
	 * @ordered
	 */
	protected float yPos = YPOS_EDEFAULT;

	/**
	 * The default value of the '{@link #getMass() <em>Mass</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getMass()
	 * @generated
	 * @ordered
	 */
	protected static final float MASS_EDEFAULT = 0.0F;

	/**
	 * The cached value of the '{@link #getMass() <em>Mass</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getMass()
	 * @generated
	 * @ordered
	 */
	protected float mass = MASS_EDEFAULT;

	/**
	 * The default value of the '{@link #getFriction() <em>Friction</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getFriction()
	 * @generated
	 * @ordered
	 */
	protected static final float FRICTION_EDEFAULT = 0.0F;

	/**
	 * The cached value of the '{@link #getFriction() <em>Friction</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getFriction()
	 * @generated
	 * @ordered
	 */
	protected float friction = FRICTION_EDEFAULT;

	/**
	 * The default value of the '{@link #getValue() <em>Value</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getValue()
	 * @generated
	 * @ordered
	 */
	protected static final int VALUE_EDEFAULT = 0;

	/**
	 * The cached value of the '{@link #getValue() <em>Value</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getValue()
	 * @generated
	 * @ordered
	 */
	protected int value = VALUE_EDEFAULT;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected AbstractEntityImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return Gamedsl2Package.Literals.ABSTRACT_ENTITY;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<Event> getEntityTriggers() {
		if (entityTriggers == null) {
			entityTriggers = new EObjectWithInverseResolvingEList<Event>(Event.class, this, Gamedsl2Package.ABSTRACT_ENTITY__ENTITY_TRIGGERS, Gamedsl2Package.EVENT__TRIGGER_ENTITY);
		}
		return entityTriggers;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<Event> getEntitySubscribers() {
		if (entitySubscribers == null) {
			entitySubscribers = new EObjectWithInverseResolvingEList.ManyInverse<Event>(Event.class, this, Gamedsl2Package.ABSTRACT_ENTITY__ENTITY_SUBSCRIBERS, Gamedsl2Package.EVENT__SUBSCRIBER_ENTITIES);
		}
		return entitySubscribers;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public AbstractEnvironment getEnvironment() {
		if (eContainerFeatureID() != Gamedsl2Package.ABSTRACT_ENTITY__ENVIRONMENT) return null;
		return (AbstractEnvironment)eContainer();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetEnvironment(AbstractEnvironment newEnvironment, NotificationChain msgs) {
		msgs = eBasicSetContainer((InternalEObject)newEnvironment, Gamedsl2Package.ABSTRACT_ENTITY__ENVIRONMENT, msgs);
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setEnvironment(AbstractEnvironment newEnvironment) {
		if (newEnvironment != eInternalContainer() || (eContainerFeatureID() != Gamedsl2Package.ABSTRACT_ENTITY__ENVIRONMENT && newEnvironment != null)) {
			if (EcoreUtil.isAncestor(this, newEnvironment))
				throw new IllegalArgumentException("Recursive containment not allowed for " + toString());
			NotificationChain msgs = null;
			if (eInternalContainer() != null)
				msgs = eBasicRemoveFromContainer(msgs);
			if (newEnvironment != null)
				msgs = ((InternalEObject)newEnvironment).eInverseAdd(this, Gamedsl2Package.ABSTRACT_ENVIRONMENT__ENTITIES, AbstractEnvironment.class, msgs);
			msgs = basicSetEnvironment(newEnvironment, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, Gamedsl2Package.ABSTRACT_ENTITY__ENVIRONMENT, newEnvironment, newEnvironment));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public String getName() {
		return name;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setName(String newName) {
		String oldName = name;
		name = newName;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, Gamedsl2Package.ABSTRACT_ENTITY__NAME, oldName, name));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public String getType() {
		return type;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setType(String newType) {
		String oldType = type;
		type = newType;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, Gamedsl2Package.ABSTRACT_ENTITY__TYPE, oldType, type));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public float getXPos() {
		return xPos;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setXPos(float newXPos) {
		float oldXPos = xPos;
		xPos = newXPos;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, Gamedsl2Package.ABSTRACT_ENTITY__XPOS, oldXPos, xPos));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public float getYPos() {
		return yPos;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setYPos(float newYPos) {
		float oldYPos = yPos;
		yPos = newYPos;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, Gamedsl2Package.ABSTRACT_ENTITY__YPOS, oldYPos, yPos));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public float getMass() {
		return mass;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setMass(float newMass) {
		float oldMass = mass;
		mass = newMass;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, Gamedsl2Package.ABSTRACT_ENTITY__MASS, oldMass, mass));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public float getFriction() {
		return friction;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setFriction(float newFriction) {
		float oldFriction = friction;
		friction = newFriction;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, Gamedsl2Package.ABSTRACT_ENTITY__FRICTION, oldFriction, friction));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public int getValue() {
		return value;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setValue(int newValue) {
		int oldValue = value;
		value = newValue;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, Gamedsl2Package.ABSTRACT_ENTITY__VALUE, oldValue, value));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case Gamedsl2Package.ABSTRACT_ENTITY__ENTITY_TRIGGERS:
				return ((InternalEList<InternalEObject>)(InternalEList<?>)getEntityTriggers()).basicAdd(otherEnd, msgs);
			case Gamedsl2Package.ABSTRACT_ENTITY__ENTITY_SUBSCRIBERS:
				return ((InternalEList<InternalEObject>)(InternalEList<?>)getEntitySubscribers()).basicAdd(otherEnd, msgs);
			case Gamedsl2Package.ABSTRACT_ENTITY__ENVIRONMENT:
				if (eInternalContainer() != null)
					msgs = eBasicRemoveFromContainer(msgs);
				return basicSetEnvironment((AbstractEnvironment)otherEnd, msgs);
		}
		return super.eInverseAdd(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case Gamedsl2Package.ABSTRACT_ENTITY__ENTITY_TRIGGERS:
				return ((InternalEList<?>)getEntityTriggers()).basicRemove(otherEnd, msgs);
			case Gamedsl2Package.ABSTRACT_ENTITY__ENTITY_SUBSCRIBERS:
				return ((InternalEList<?>)getEntitySubscribers()).basicRemove(otherEnd, msgs);
			case Gamedsl2Package.ABSTRACT_ENTITY__ENVIRONMENT:
				return basicSetEnvironment(null, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eBasicRemoveFromContainerFeature(NotificationChain msgs) {
		switch (eContainerFeatureID()) {
			case Gamedsl2Package.ABSTRACT_ENTITY__ENVIRONMENT:
				return eInternalContainer().eInverseRemove(this, Gamedsl2Package.ABSTRACT_ENVIRONMENT__ENTITIES, AbstractEnvironment.class, msgs);
		}
		return super.eBasicRemoveFromContainerFeature(msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case Gamedsl2Package.ABSTRACT_ENTITY__ENTITY_TRIGGERS:
				return getEntityTriggers();
			case Gamedsl2Package.ABSTRACT_ENTITY__ENTITY_SUBSCRIBERS:
				return getEntitySubscribers();
			case Gamedsl2Package.ABSTRACT_ENTITY__ENVIRONMENT:
				return getEnvironment();
			case Gamedsl2Package.ABSTRACT_ENTITY__NAME:
				return getName();
			case Gamedsl2Package.ABSTRACT_ENTITY__TYPE:
				return getType();
			case Gamedsl2Package.ABSTRACT_ENTITY__XPOS:
				return getXPos();
			case Gamedsl2Package.ABSTRACT_ENTITY__YPOS:
				return getYPos();
			case Gamedsl2Package.ABSTRACT_ENTITY__MASS:
				return getMass();
			case Gamedsl2Package.ABSTRACT_ENTITY__FRICTION:
				return getFriction();
			case Gamedsl2Package.ABSTRACT_ENTITY__VALUE:
				return getValue();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case Gamedsl2Package.ABSTRACT_ENTITY__ENTITY_TRIGGERS:
				getEntityTriggers().clear();
				getEntityTriggers().addAll((Collection<? extends Event>)newValue);
				return;
			case Gamedsl2Package.ABSTRACT_ENTITY__ENTITY_SUBSCRIBERS:
				getEntitySubscribers().clear();
				getEntitySubscribers().addAll((Collection<? extends Event>)newValue);
				return;
			case Gamedsl2Package.ABSTRACT_ENTITY__ENVIRONMENT:
				setEnvironment((AbstractEnvironment)newValue);
				return;
			case Gamedsl2Package.ABSTRACT_ENTITY__NAME:
				setName((String)newValue);
				return;
			case Gamedsl2Package.ABSTRACT_ENTITY__TYPE:
				setType((String)newValue);
				return;
			case Gamedsl2Package.ABSTRACT_ENTITY__XPOS:
				setXPos((Float)newValue);
				return;
			case Gamedsl2Package.ABSTRACT_ENTITY__YPOS:
				setYPos((Float)newValue);
				return;
			case Gamedsl2Package.ABSTRACT_ENTITY__MASS:
				setMass((Float)newValue);
				return;
			case Gamedsl2Package.ABSTRACT_ENTITY__FRICTION:
				setFriction((Float)newValue);
				return;
			case Gamedsl2Package.ABSTRACT_ENTITY__VALUE:
				setValue((Integer)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case Gamedsl2Package.ABSTRACT_ENTITY__ENTITY_TRIGGERS:
				getEntityTriggers().clear();
				return;
			case Gamedsl2Package.ABSTRACT_ENTITY__ENTITY_SUBSCRIBERS:
				getEntitySubscribers().clear();
				return;
			case Gamedsl2Package.ABSTRACT_ENTITY__ENVIRONMENT:
				setEnvironment((AbstractEnvironment)null);
				return;
			case Gamedsl2Package.ABSTRACT_ENTITY__NAME:
				setName(NAME_EDEFAULT);
				return;
			case Gamedsl2Package.ABSTRACT_ENTITY__TYPE:
				setType(TYPE_EDEFAULT);
				return;
			case Gamedsl2Package.ABSTRACT_ENTITY__XPOS:
				setXPos(XPOS_EDEFAULT);
				return;
			case Gamedsl2Package.ABSTRACT_ENTITY__YPOS:
				setYPos(YPOS_EDEFAULT);
				return;
			case Gamedsl2Package.ABSTRACT_ENTITY__MASS:
				setMass(MASS_EDEFAULT);
				return;
			case Gamedsl2Package.ABSTRACT_ENTITY__FRICTION:
				setFriction(FRICTION_EDEFAULT);
				return;
			case Gamedsl2Package.ABSTRACT_ENTITY__VALUE:
				setValue(VALUE_EDEFAULT);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case Gamedsl2Package.ABSTRACT_ENTITY__ENTITY_TRIGGERS:
				return entityTriggers != null && !entityTriggers.isEmpty();
			case Gamedsl2Package.ABSTRACT_ENTITY__ENTITY_SUBSCRIBERS:
				return entitySubscribers != null && !entitySubscribers.isEmpty();
			case Gamedsl2Package.ABSTRACT_ENTITY__ENVIRONMENT:
				return getEnvironment() != null;
			case Gamedsl2Package.ABSTRACT_ENTITY__NAME:
				return NAME_EDEFAULT == null ? name != null : !NAME_EDEFAULT.equals(name);
			case Gamedsl2Package.ABSTRACT_ENTITY__TYPE:
				return TYPE_EDEFAULT == null ? type != null : !TYPE_EDEFAULT.equals(type);
			case Gamedsl2Package.ABSTRACT_ENTITY__XPOS:
				return xPos != XPOS_EDEFAULT;
			case Gamedsl2Package.ABSTRACT_ENTITY__YPOS:
				return yPos != YPOS_EDEFAULT;
			case Gamedsl2Package.ABSTRACT_ENTITY__MASS:
				return mass != MASS_EDEFAULT;
			case Gamedsl2Package.ABSTRACT_ENTITY__FRICTION:
				return friction != FRICTION_EDEFAULT;
			case Gamedsl2Package.ABSTRACT_ENTITY__VALUE:
				return value != VALUE_EDEFAULT;
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public String toString() {
		if (eIsProxy()) return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (name: ");
		result.append(name);
		result.append(", type: ");
		result.append(type);
		result.append(", xPos: ");
		result.append(xPos);
		result.append(", yPos: ");
		result.append(yPos);
		result.append(", mass: ");
		result.append(mass);
		result.append(", friction: ");
		result.append(friction);
		result.append(", value: ");
		result.append(value);
		result.append(')');
		return result.toString();
	}

} //AbstractEntityImpl
